package alogrithm;

/**
 * @author lbw
 * @date 2021/10/16 15:56
 * @version 1.0
 */
public class MaxProfit {

    public int maxProfit (int[] prices) {
        // write code here
        int n = prices.length;
        int res = 0;
        int min = prices[0];
        for (int i = 1; i < n; ++i) {
            if (prices[i] < min) {
                min = prices[i];
            }
            res = Math.max(res, prices[i] - min);
        }
        return res;
    }
}
